<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of RepFacturaDetallada
 *
 * @author Bryan Cruz
 */
class RepStudCarrera extends ReportBase {
    
    public $where = NULL;
    public $stud = "";

    function __construct() {
        $this->callbackSql = "cbSqlGenerador"; //funcion que genera sql
        $this->callbackRow = "funcRows"; //funcion para cada fila generada
        $this->paramPage = "rpt_studCarrera_param.php";
        $this->resultPage = "rpt_studCarrera_resultado.php";
        $this->rootPath = RPT_PATH + "include";
        $this->label = "Alumnos por Carrera";
        $this->subtitle = $this->label;
    }

    public function funcRows() {
        $newResult = array();
        foreach ($this->lastResult as $r) {
            $sql = "select * from cllg_factura";
            $rs = $this->query($sql);
            
        }
        $this->lastResult = $newResult;
    }

    /**
     * Genera el sql para el reporte
     */
    public function getFields() {
        #$this->fields = isset($_POST['selFields']) ? NULL : $_POST['selFields'];
         if (isset($_POST['selFields'])){
             return $_POST['selFields'];
         }
    }
    
    public function cbSqlGenerador() {
        #EaPdfPrinter::$ORIENTACION = "landscape";
        #$user = AppSecurity::$UserData;
        #$user = $user["data"];
           
        $sql = "SELECT * FROM cllg_student_assign ";
        $w = NULL;

        if (!isEmpty(getParam("cycle"))) {
            $w = isEmpty($w) ? $w : "$w and ";
            $w.=sprintf("FK_CYCLE='%s'", getParam("cycle"));
        }
        
        if (!isEmpty(getParam("career"))) {
            $w = isEmpty($w) ? $w : "$w and ";
            $w.=sprintf("FK_CAREER='%s'", getParam("career"));
        }
        
        if(!isEmpty(getParam("LUNES")) || !isEmpty(getParam("MARTES")) || !isEmpty(getParam("MIERCOLES")) || !isEmpty(getParam("JUEVES")) || !isEmpty(getParam("VIERNES")) || !isEmpty(getParam("SABADO"))){
            $w = isEmpty($w) ? $w : "$w and ";
            $w.="cllg_student_assign.ID IN (
                        SELECT a.ID
                        FROM cllg_student_assign a, cllg_assign_detail b, cllg_teacher_assign c
                        WHERE a.ID=b.FK_ASSIGN and b.SECTION=c.SECTION and b.FK_COURSE=c.FK_COURSE ";
            if(!isEmpty(getParam("LUNES"))){
                $w = isEmpty($w) ? $w : "$w and ";
                $w.="LUNES = 1";
            }
            if(!isEmpty(getParam("MARTES"))){
                $w = isEmpty($w) ? $w : "$w and ";
                $w.="MARTES = 1";
            }
            if(!isEmpty(getParam("MIERCOLES"))){
                $w = isEmpty($w) ? $w : "$w and ";
                $w.="MIERCOLES = 1";
            }
            if(!isEmpty(getParam("JUEVES"))){
                $w = isEmpty($w) ? $w : "$w and ";
                $w.="JUEVES = 1";
            }
            if(!isEmpty(getParam("SABADO"))){
                $w = isEmpty($w) ? $w : "$w and ";
                $w.="SABADO = 1";
            }
            if(!isEmpty(getParam("VIERNES"))){
                $w = isEmpty($w) ? $w : "$w and ";
                $w.="VIERNES = 1";
            }
            $w.=")";
        }
            
        if(getParam("career") == 0 || getParam("cycle") == 0){
                throw new Exception("<h5 style='color:blue;'>Seleccione carrera y ciclo!!<h5>");
        }
        
        $this->lastQuery = isEmpty($w) ? $sql : ("$sql WHERE $w AND STATUS=1");
    }
 
    
    
    public function generateSQL() {
        
        $this->cbSqlGenerador();
        $sqlRs = $this->db->queryToArray($this->lastQuery);
        $this->lastResult = $sqlRs;
    }
    
    public function setCol($startRow,$tab){
        $fields = array();
        $result = "";
        $fields = $this->db->query_select("cllg_tablefield","TABLE_NAME='cllg_student' AND STATUS !=0 AND FK_TAB=$tab LIMIT $startRow,5");
        foreach($fields as $f){
            $result .= "<td width='2%'><input type='checkbox' name='selFields[]' id='". $f['NAME'] ."' value='". $f['NAME'] ."' />";
            $result .= "<td width='18%' style='padding-top:0.3%;padding-bottom:0'><label for='". $f['NAME'] ."'>". $f['CAPTION']."</label>";        
        }
        return $result;
    }
    
    public function getBaseFields(){
        #$this->fields = isset($_POST['selFields']) ? NULL : $_POST['selFields'];
         if (isset($_POST['baseFields'])){
             return $_POST['baseFields'];
         }
    
    }
}
?>
